#ifndef MSTSTATISTICS_H
#define MSTSTATISTICS_H

#include <cstdint>
#include <atomic>
#include <memory>
#include <string>

struct MstStatistics
{
public:
    MstStatistics(size_t maxBuffer) : m_bufferMaxSize(maxBuffer) {}
    size_t currBufferSize  { 0 };
    size_t rxBytes { 0 };
    size_t rxValidBytes { 0 };
    size_t rxPkg { 0 };
    size_t rxPkgHead { 0 };
    size_t bytesAvailable { 0 };
    double rxErrorRate() const { return 100.0 - rxValidBytes * 100.0 / rxBytes; }
    double rxLoadRate() const { return currBufferSize * 100.0 / m_bufferMaxSize; }
    size_t dRxBytes()
    {
        size_t dRxBytes = rxBytes - lastRxBytes;
        lastRxBytes = rxBytes;
        return dRxBytes;
    }
    std::string portName;
    bool isPortReady { false };
private:
    std::atomic<size_t> lastRxBytes { 0 };
    size_t m_bufferMaxSize { 0 };
};

using MstStatisticsHandle = std::shared_ptr<MstStatistics>;

#endif // MSTSTATISTICS_H
